/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Objects;

import GameEngine.GameConstants.Effect;
import GameEngine.GameConstants.Graphic;
import GameEngine.GameConstants.Material;
import GameEngine.Vector;

/**
 *
 * @author jh20
 */
public class Vacuum extends GameObject {

    // instance variables
    private int vacPower;


    public Vacuum(Vector d, Vector cen, Vector s) {
        super(d, cen, s, Graphic.VACUUM);
        material = Material.WALL;
    }

    /**
     * "copy" constructor
     * @param fan
     */

    public Vacuum(Fan fan) {
        super(fan.getDir(), fan.getCenter(), fan.getSize(), Graphic.VACUUM);
        material = Material.WALL;
    }

    /* set the strenght of the fan */
    public void setVacPower(int strength) {
        vacPower = strength;
    }

    public int getVacPower() {
        return vacPower;
    }

     /** this method will be called on every object at the beginning of every iteration. In this method
     * particular objects may do specific things, such as arbitrarily update their own attributes based
     * on some correlation to their lifetime (how long they've existed...eg chompers updating their deltaPosition
     * up or down), or even causing an effect on other objects. But every object must iterate through the
     * list of persistent effects on them and receive them.
     */
    @Override
    public void nextIteration() {
        // first apply persistent
        super.applyPersistent();

        if (lifetime % 20 == 0) {

            /* create wind to be direction you face */
            Vector windSize = new Vector(2.2*size.getX(), size.getY());

            Vector windCen = direction.scaleNew(2.2*size.getX() - size.getX()/2);
            windCen.add(center);

            Wind toCreate = new Wind(direction.scaleNew(-1), windCen, windSize, Graphic.WIND);
            toCreate.setWind(direction.scaleNew((double) -vacPower));
            /* tell parent you created this object */
            lev.createObject(toCreate);
        }
        
        // then do physics
        super.doPhysics();
        // then undo persitent
        super.cancelPersistent();
    }


    @Override
    public void receiveEffect(Effect e, Vector m, int power) {
        switch (e) {
            case TRANSMUTE:
                Fan fan = new Fan(this);
                fan.setFanPower(vacPower);
                lev.createObject(fan);
                this.receiveEffect(Effect.DESTROY, null, 0);
                break;
            case SPEED:
                changed = true;
                vacPower += power;
                break;
            case SLOW:
                changed = true;
                vacPower -= power;
                break;
            case CURRENT:
                // do nothing
                break;
            default:
                super.receiveEffect(e, m, power);
                break;
        }
    }

}
